package cn.edu.ujn.service;

import cn.edu.ujn.dao.Login;
import cn.edu.ujn.dao.LoginMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoginServiceImpl implements ILoginService{
    @Autowired
    private LoginMapper loginMapper;
    @Override
    public Login login(String username, String password) {
        return loginMapper.findByUsernameAndPassword(username, password);
    }

    @Override
    public int addUser(Login login) {
        return loginMapper.insertLogin(login);
    }

    @Override
    public int updateUser(Login login) {
        return loginMapper.updateLogin(login);
    }

    @Override
    public int deleteUser(int userId) {
        return loginMapper.deleteLogin(userId);
    }

    @Override
    public Login getUserById(int userId) {
        return loginMapper.selectLoginById(userId);
    }

    @Override
    public List<Login> getAllUsers() {
        return loginMapper.selectAllLogins();
    }

    @Override
    public boolean isUsernameTaken(String username) {
        return loginMapper.selectLoginByUsername(username) != null; // 返回是否存在该用户名
    }
}
